import {defineStore} from "pinia"
import {login,refreshToken} from "../utils/api"

export const useLoginStore = defineStore("login",{
    persist:true,
    state:()=>{
        return {
            loginUser:null
        }
    },
    actions:{
        async login(phone,password){
            let loginData = await login(phone,password);
            if(loginData.data.errorCode=='0000'){
                this.loginUser=loginData.data.data;
            }
            return loginData.data;
        },
        async refreshToken(){
            let {data} = await refreshToken();
            let tokenVo = data.data;
            if(tokenVo){
                this.loginUser.tokenVo=tokenVo;
            }else{
                this.loginUser=null;
            }
        }
    }
})